<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: order_history.php 140 2013-09-22 07:44:23Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 140 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:44:23 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

if (isset($_SESSION['customer_id'])) {
	$box_smarty = new smarty;

	if (isset($_SESSION['customer_id'])) {
		$orders = $db->db_query_limit("SELECT DISTINCT 
											op.products_id 
										FROM 
											".TABLE_ORDERS." o, 
											".TABLE_ORDERS_PRODUCTS." op, 
											".TABLE_PRODUCTS." p 
										WHERE 
											o.customers_id = '".(int)$_SESSION['customer_id']."' 
										AND 
											o.orders_id = op.orders_id 
										AND 
											op.products_id = p.products_id 
										AND 
											p.products_status = '1' 
										GROUP BY 
											op.products_id 
										ORDER BY 
											o.date_purchased DESC ", MAX_DISPLAY_PRODUCTS_IN_ORDER_HISTORY_BOX);
		if ($orders_query->_numOfRows) {
			$product_ids = '';
			while (!$orders->EOF) {
				$product_ids .= $orders['products_id'].',';
				$orders->MoveNext();
			}
			$product_ids = substr($product_ids, 0, -1);

			$customer_orders_string = '<table border="0" width="100%" cellspacing="0" cellpadding="1">';
			$products = $db->db_query("SELECT products_id, products_name from ".TABLE_PRODUCTS_DESCRIPTION." WHERE products_id in (".$product_ids.") and language_id = '".(int)$_SESSION['languages_id']."' ORDER BY products_name");
			while (!$products->EOF) {
				$customer_orders_string .= ' <tr>' .
			                           '    <td class="infoBoxContents"><a href="'.href_link(FILENAME_PRODUCT_INFO, product_link($products->fields['products_id'],$products->fields['products_name'])).'">'.$products->fields['products_name'].'</a></td>' .
			                           '    <td class="infoBoxContents" align="right" valign="top"><a href="'.href_link(basename($PHP_SELF), get_all_get_params(array('action')).'action=cust_order&pid='.$products->fields['products_id']).'">'.image(DIR_WS_ICONS.'cart.gif', ICON_CART).'</a></td>' .
			                           '  </tr>';
			    $products->MoveNext();
			}
			$customer_orders_string .= '</table>';
		}
	}

	$box_smarty->assign('BOX_CONTENT', $customer_orders_string);

	$box_smarty->caching = false;
	$box_smarty->assign('language', $_SESSION['language']);
	$box_smarty->assign('tpl_path','templates/'.CURRENT_TEMPLATE.'/');
	$box_smarty->assign('html_tpl_path', CURRENT_TEMPLATE.'/html');

	$box_content = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_order_history.html');
}
?>